﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for BLLForgetPassword
/// </summary>
public class BLLForgetPassword
{
	public BLLForgetPassword()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    //Sending email to user
    public void sendEmail(string emailto)
    {
        string password = randomPassword();
        Hash cipher = new Hash();
        DALCustomer dalCustomer = new DALCustomer();
        tblCustomer customer = dalCustomer.getPassword(emailto);
        customer.Password = cipher.hash(password);
        dalCustomer.updateCustomer(customer);

        Email email = new Email();
        string subject = "Mail Maintainer Password Recovery";
        string content = "<p><strong>Dear Customer</strong>,</p><p>	Please Login with the following password</p><p>    " + password + "</p><p>	You are are adviced to change your password after you loged in to the system.</p><p>	If you have any questions about your account or any other matter, please feel free to contact us at <u>feedback@mailmaintainer.com</u></p><p>	It will be our pleasure to serve you.</p>";

        email.sendEmail(emailto, "teoshaoqi@gmail.com", subject, content);
    }

    //Pass
    public string randomPassword()
    {
        string allowedChars = "";
        allowedChars = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,";
        allowedChars += "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,";
        allowedChars += "1,2,3,4,5,6,7,8,9,0,!,@,#,$,%,&,?";

        char[] sep = { ',' };

        string[] arr = allowedChars.Split(sep);

        string passwordString = "";

        string temp = "";

        Random rand = new Random();

        for (int i = 0; i < 8; i++)
        {
            temp = arr[rand.Next(0, arr.Length)];
            passwordString += temp;
        }
        return passwordString;
    }
}